package com.rr.intTest;

/**
 * Java类型转换: int转String
 *
 * @author : RENBIAO
 * @createTime : 2021/6/17 14:46
 */
public class intToString {

    public static void main(String[] args) {

        int intNum1 = 0;
        int intNum2 = 6;
        int intNum3 = -865;

        //方法1：直接+""
        String stringNum1 = intNum1 + "";
        String stringNum2 = intNum2 + "";
        String stringNum3 = intNum3 + "";
        System.out.println("intNum1转换后为【转换方法:直接+\"\"】:" + stringNum1);
        System.out.println("intNum2转换后为【转换方法:直接+\"\"】:" + stringNum2);
        System.out.println("intNum3转换后为【转换方法:直接+\"\"】:" + stringNum3);

        //方法2：String.valueOf()
        String stringNum4 = String.valueOf(intNum1);
        String stringNum5 = String.valueOf(intNum2);
        String stringNum6 = String.valueOf(intNum3);
        System.out.println("intNum1转换后为【转换方法:String.valueOf()】:" + stringNum4);
        System.out.println("intNum2转换后为【转换方法:String.valueOf()】:" + stringNum5);
        System.out.println("intNum3转换后为【转换方法:String.valueOf()】:" + stringNum6);

        //方法3：Integer.toString()
        String StringNum7 = Integer.toString(intNum1);
        String StringNum8 = Integer.toString(intNum2);
        String StringNum9 = Integer.toString(intNum3);
        System.out.println("intNum1转换后为【转换方法:Integer.toString()】:" + StringNum7);
        System.out.println("intNum2转换后为【转换方法:Integer.toString()】:" + StringNum8);
        System.out.println("intNum3转换后为【转换方法:Integer.toString()】:" + StringNum9);

    }
}
